import 'package:flutter_chubao/tools/shared/app_share_constant.dart';
import 'package:shared_preferences/shared_preferences.dart';

class AppSharedPro {
  static late SharedPreferences sharedPreferences;
  static Future<bool> setBool(String key, bool value) async {
    return await sharedPreferences.setBool(key, value);
  }

  static bool getBool(String key, {bool defaultValue = false}) {
    return sharedPreferences.getBool(key) ?? false;
  }

  static Future<bool> setInt(String key, int value) async {
    return await sharedPreferences.setInt(key, value);
  }

  static int getInt(String key) {
    return sharedPreferences.getInt(key) ?? 0;
  }

  static Future<bool> setDouble(String key, double value) async {
    return await sharedPreferences.setDouble(key, value);
  }

  static double getDouble(String key) {
    return sharedPreferences.getDouble(key) ?? 0.0;
  }

  static Future<bool> setString(String key, String value) async {
    return await sharedPreferences.setString(key, value);
  }

  static String getString(String key) {
    return sharedPreferences.getString(key) ?? "";
  }

  /// 清除本地缓存
  static remove() async {
    String deviceId = getString(AppShareConstant.deviceId);
    sharedPreferences.clear();
    setString(AppShareConstant.deviceId, deviceId);
  }

  static removeOnly(String key) async {
    sharedPreferences.remove(key);
  }
}
